﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算时间差</title>
    <script type="text/javascript">
        function calTime()
        {
            let time1 = new Date().setHours(12,25,30);  //三个参数分别是小时、分、秒
            let time2 = new Date().setHours(20,12,10);  //创建另一个时间
            let timeDiff = time2 - time1;               //获取两个时间差，结果为毫秒
            timeDiff = timeDiff / (60 * 60 * 1000);           //毫秒换算成小时
            return timeDiff;
        }
    </script>
</head>
<body>
<input type=button value="计算" onClick="alert (calTime())">
</body>
</html>